package com.ruoyi.system.controller.Evaluating;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.Evaluating.EvaluationRecord;
import com.ruoyi.system.domain.dto.EvaluationRecordSearchDto;
import com.ruoyi.system.service.Evaluating.IEvaluationRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;

/**
 * 操作记录Controller
 * 前端方面：路由路径未改
 * 功能需求方面：需求模糊，操作记录的min,max,avg意义模糊，建议谨慎考虑此需求
 * 增删改查：随评价结果增，不应该有删，不应该有改，提供原本查询
 * @author zdm
 * @date 2024-07-04
 */
@RestController
@RequestMapping("/system/record")
public class EvaluationRecordController extends BaseController
{
    @Autowired
    private IEvaluationRecordService evaluationRecordService;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(
            @RequestParam(value="pageNum",required = false) String pageNum,
            @RequestParam(value="pageSize",required = false)String pageSize,
            EvaluationRecord evaluationRecord)
    {
        startPage();
        List<EvaluationRecord> list = evaluationRecordService.selectEvaluationRecordList(evaluationRecord);
        return getDataTable(list);
    }


    @PreAuthorize("@ss.hasPermi('system:record:search')")
    @GetMapping("/search")
    public TableDataInfo selectBySearch(@RequestParam(value="id",required = false) String id,
                                     @RequestParam(value="projectName",required = false) String projectName,
                                     @RequestParam(value="evaluationName",required = false) String evaluationName,
                                     @RequestParam(value="startDate",required = false) String startDate,
                                     @RequestParam(value="endDate",required = false)String endDate,
                                        @RequestParam(value="pageNum",required = false) String pageNum,
                                        @RequestParam(value="pageSize",required = false)String pageSize) {

        startPage();
        EvaluationRecordSearchDto evaluationRecordSearchDto=new EvaluationRecordSearchDto();
        evaluationRecordSearchDto.setId(id);
        evaluationRecordSearchDto.setProjectName(projectName);
        evaluationRecordSearchDto.setEvaluationName(evaluationName);
        evaluationRecordSearchDto.setStartDate(startDate);
        evaluationRecordSearchDto.setEndDate(endDate);
        System.out.println(evaluationRecordSearchDto);
        List<EvaluationRecord> list =evaluationRecordService.searchEvaluationRecordList(evaluationRecordSearchDto);
        return getDataTable(list);
    }
    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:record:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EvaluationRecord evaluationRecord)
    {
        List<EvaluationRecord> list = evaluationRecordService.selectEvaluationRecordList(evaluationRecord);
        ExcelUtil<EvaluationRecord> util = new ExcelUtil<EvaluationRecord>(EvaluationRecord.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(evaluationRecordService.selectEvaluationRecordById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:record:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EvaluationRecord evaluationRecord)
    {
        return toAjax(evaluationRecordService.insertEvaluationRecord(evaluationRecord));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:record:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EvaluationRecord evaluationRecord)
    {
        return toAjax(evaluationRecordService.updateEvaluationRecord(evaluationRecord));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:record:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(evaluationRecordService.deleteEvaluationRecordByIds(ids));
    }
}
